package edu.cuit.avatar.generic;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/19 10:32
 */
public class GenericMethodParameterTest {
    public void test(List<String> list){
        System.out.println(list.size());
        //System.out.println(void.class);
    }

    public List<String> demo(){
        return new ArrayList<>();
    }

    public static void main(String[] args)  throws Exception{
        Class<GenericMethodParameterTest> clazz = GenericMethodParameterTest.class;
        var method = clazz.getDeclaredMethod("test", List.class);
        var type = method.getGenericParameterTypes()[0];

        if(type instanceof ParameterizedType pd){
            System.out.println(pd.getRawType());
            System.out.println(pd.getActualTypeArguments()[0].getTypeName());
            System.out.println(pd.getOwnerType());
        }

        var demo = clazz.getDeclaredMethod("demo");
        Type returnType = demo.getGenericReturnType();
        if(returnType instanceof ParameterizedType pd){
            System.out.println(pd.getRawType());
            System.out.println(pd.getActualTypeArguments()[0].getTypeName());
        }
    }
}
